// pages/tablehub/index.js
const app = getApp();
import config from "../../config";
import dayjs from "dayjs";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    days_cn: ['一', '二', '三', '四', '五', '六', '日'],
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    colorList: config.colorList,
    selfCourse: []
  },
  /**删除课程 */
  delCourse(e){
    console.log(e)
    var that = this;
    let idx = e.currentTarget.dataset.idx;
    let id = e.currentTarget.dataset.id;
    let selfCourse = this.data.selfCourse;
    wx.showModal({
      title:'提醒',
      content:`是否要删除${selfCourse[idx].coursename}`,
      success:r=>{
        if(r.confirm){
          wx.showLoading({
            title: '删除中',
          })
          wx.cloud.callFunction({
            name:'edu-timetable-api',
            data:{
              action:'deleteCustom',
              docId:id
            },
            success:res=>{
              selfCourse.splice(idx,1)
              that.setData({
                selfCourse
              })
            },
            complete:res=>{
              wx.hideLoading();
            }
          })
        }
      }
    })
  },
  /**返回上一页 */
  BackPage() {
    wx.navigateBack({
      delta: 0,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // wx.showToast({
    //   title: '正在构建',
    //   icon:'loading'
    // })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    wx.showLoading({
      title: '查询中'
    })
    wx.cloud.callFunction({
      name: 'edu-timetable-api',
      data: {
        action: 'getUserTable'
      },
      success: res => {
        that.setData({
          selfCourse: res.result.data
        })
      },
      complete: res => {
        wx.hideLoading();
        console.log(res)
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})